<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="投标单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderUnit">
<!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderUnit" dictCode="erp_company_files,file_name,id,del_flag=0 and audit_status=2" placeholder="请选择投标单位"/>-->
<!--              <j-select-company :disabled="disabled" v-model="model.tenderUnit"/>-->
              <a-input :disabled="disabled" v-model="model.tenderUnit" placeholder="请输入投标单位"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="投标金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAmount">
              <a-input :disabled="disabled" v-model="model.tenderAmount" placeholder="请输入投标金额"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="中标结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidResult">
              <j-dict-select-tag :disabled="disabled" type="list" v-model="model.bidResult" dictCode="bid_result" placeholder="请选择中标结果"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instruction">
              <a-textarea :disabled="disabled" v-model="model.instruction" rows="4" placeholder="请输入说明"/>
            </a-form-model-item>
          </a-col>
          <!--迭代11 去除项目负责人，难度系数，成果系数等字段 -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import SelectUserByDep from '@/views/scy/components/SelectUserByDep';
import { message } from 'ant-design-vue';
import { postAction, putAction } from '../../../../../api/manage';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
export default {
  name: 'ErpOmcTenderResultUnitForm',
  components: {
    SelectUserByDep,
    SelectCompanyInput
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: true,
      required: false
    },
    // 子表中是否已有中标数据
    isWinTheBid:{
      type: Boolean,
      default: false,
      required: false
    },
    hasBid:{
          type: Boolean,
          default: false,
          required: false
      },
    formDisabledEdit:{
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        tenderUnit: [
          { required: true, message: '请选择投标单位!' },
        ],
        tenderAmount: [
          { pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' },
        ],
        bidResult: [
          { required: true, message: '请选择中标结果!' }
        ],
        complexCoefficient: [
          { required: false },
          { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' },
        ],
        resultCoefficient: [
          { required: false },
          { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' },
        ],
      },
      url: {
        add: '/api/erp/omc/tenderresult/erpOmcTenderResultUnit/add',
        edit: '/api/erp/omc/tenderresult/erpOmcTenderResultUnit/edit',
        queryById: '/api/erp/omc/tenderresult/erpOmcTenderResultUnit/queryById',
      },
      unitDictCode: 'erp_company_files,file_name,id, del_flag = 0',
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    // 自定义表单验证规则 子表中已有中标记录(this.isWinTheBid=true)不可再添加中标记录
    add() {
      this.edit(this.modelDefault);
    },
    //审核时修改系数和成果
    editComplexCoefficient(){
      if(this.formDisabledEdit&&this.model&&this.model.id!=null){
        putAction(this.url.edit,this.model).then(res=>{
          console.log(res)
        })
      }
    },
    edit(record) {
      this.$refs['form'].clearValidate();
      Object.assign(this.$data, this.$options.data())
      // this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 已经有投标了
      if(this.model.bidResult=="1" && this.isWinTheBid && this.hasBid){
        this.$message.warning("已有中标单位!")
        this.model.bidResult = null
      }

      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          //debugger;
          if (!this.model.id) {
            this.model.id = parseInt(Math.random() * 1000000000000);
          }
          that.$emit('ok', this.model);
        }

      })
    },
  }
}
</script>
